param(
    [Parameter(Mandatory, Position=0)]
    [string]$Path,

    [switch]$Web
)

$src = $Path
if ($Web) {
    $dst = $Path -replace '\.tif$', '_cgo_web.tif'
}
else {
    $dst = $Path -replace '\.tif$', '_cgo.tif'
}

# https://cogeotiff.github.io/rio-cogeo/CLI/
# --zoom-level-strategy : auto|lower|upper
# --resampling : nearest|bilinear|cubic|cubic_spline|lanczos|average|mode|max|min|med|q1|q3|sum
$createArgs = @(
    '--bidx', '1,2,3',
    # '--add-mask',
    '--blocksize=512',
    # --co BLOCKXSIZE=512 `
    # --co BLOCKYSIZE=512 `
    # '--forward-band-tags',
    # '--forward-ns-tags',
    '--dtype=uint8',
    '--allow-intermediate-compression',
    '--cog-profile=deflate',
    # '--cog-profile=jpeg',
    '--threads=ALL_CPUS',
    '--use-cog-driver',

    # '--zoom-level-strategy=auto',
    # '--zoom-level=6',

    $src, $dst
)
if ($Web) {
    $createArgs += @(
        '--web-optimized',
        '--resampling=lanczos'
    )
}

& rio cogeo create @createArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

& rio cogeo validate $dst
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

& rio cogeo info $dst
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
